package com.ruoyi.web.controller.culturalyard;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.dto.CameraPageQueryDTO;
import com.ruoyi.common.core.domain.vo.CameraPageVO;
import com.ruoyi.common.core.domain.vo.CameraVO;
import com.ruoyi.system.service.CameraService;
import com.ruoyi.system.service.impl.OpenApiServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/camera")
public class CameraController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(CameraController.class);

    @Autowired
    private CameraService cameraService;

    public static final String KEY = "accessToken";

    /**
     * 根据摄像头id获取摄像头
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable String id){
        log.info("查询监控：{}",id);
        CameraVO cameraVO = cameraService.getByIdWithYardName(id);
        return AjaxResult.success(cameraVO);
    }

    /**
     * 分页查询监控数据
     * @param cameraPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public AjaxResult page(CameraPageQueryDTO cameraPageQueryDTO){
        log.info("分页查询监控数据：{}", cameraPageQueryDTO);
        return AjaxResult.success(cameraService.pageQuery(cameraPageQueryDTO));
    }

    /**
     * 根据id更新摄像头置顶状态
     * @param topStatus  (0为非置顶，1为置顶)
     * @param id
     * @return
     */
    @PostMapping("/topStatus/{topStatus}")
    public AjaxResult updateTopStatusById(@PathVariable Integer topStatus,String id){
        log.info("根据id更新摄像头置顶状态:{},{}",id,topStatus);
        cameraService.updateTopStatusById(id,topStatus);
        return success();
    }

    /**
     * 根据id更新摄像头是否在常时监控区
     * @param managementAreaStatus  (0为不在常时监控区，1为在常时监控区)
     * @param id
     * @return
     */
    @PostMapping("/managementAreaStatus/{managementAreaStatus}")
    public AjaxResult updateManagementAreaStatusById(@PathVariable Integer managementAreaStatus, String id){
        log.info("根据id更新摄像头常时监控区状态:{},{}",id,managementAreaStatus);
        cameraService.updateManagementAreaStatusById(id,managementAreaStatus);
        return success();
    }

    /**
     * 根据id将已经在常时监控区的摄像头置顶到常时监控区
     * @param id
     * @return
     */
    @PostMapping("/managementArea/topStatus/{id}")
    public AjaxResult updateManagementAreaTopStatusById(@PathVariable String id){
        log.info("根据id更新摄像头常时监控区置顶状态:{}",id);
        cameraService.updateManagementAreaTopStatusById(id);
        return success();
    }

    /**
     * 根据摄像头id请求新的token
     * @param id
     * @return
     */
    @PostMapping("/token/{id}")
    public AjaxResult getTokenById(@PathVariable String id){
        log.info("请求更新token：{}",id);
        String token = cameraService.updateTokenById(id);
        return AjaxResult.success(token);
    }

    /**
     * 分页查询常时监控区摄像头
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/managementArea")
    public AjaxResult getManagementArea(Integer page,Integer size){
        log.info("分页查询常时监控区的监控数据：{},{}", page,size);
        return AjaxResult.success(cameraService.pageManagementArea(page,size));
    }

}
